<?php
    require_once '../../Database/Database.php';

    function ConvertLength($length)
    {
        return ($length / 1000);
    }
?>
<?php
    if(isset($_GET['id']))
    {
        $db = new Database();
        $db->Connect();

        $id = $_GET['id'];

        echo '<div class="add"><a href="add_track.php?id=' . $id . '" target="_blank"><img src="../../Icons/add_track.png" /></a></div>';

        $shortcut = $db->SelectColumns('Series', 'Shortcut', 'ID_Series = ' . $id);

        $tracks = $db->Select($shortcut[0]->Shortcut . '_tracks');

        if($tracks)
        {
            echo '<table><tr><td>Name</td><td>L&auml;nge</td><td>Rundenanzahl</td><td>Ort</td></tr><tr><td>';
            foreach($tracks as $track)
            {
                echo $track->Name . '</td><td>';
                echo ConvertLength($track->Length) . ' km</td><td>';
                echo $track->Laps . '</td><td>';
                echo $track->Location . '</td></tr>';
            }
            echo '</table>';
        }
        else
        {
            echo 'Keine Strecken eingetragen.';
        }
    }
    else
    {
        echo 'Ungültige Serien ID';
    }
    $db->Disconnect();
?>
